﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace HelloWPF.DependencyAttachedProperty
{
    /// <summary>
    /// GridAttachedAttributeToButton.xaml 的交互逻辑
    /// </summary>
    public partial class GridAttachedAttributeToButton : Window
    {
        public GridAttachedAttributeToButton()
        {
            InitializeComponent();

            InitializeLauout();
        }

        /// <summary>
        /// 初始化布局
        /// 在C#代码中为附加属性赋值
        /// </summary>
        private void InitializeLauout()
        {
            Grid grid = new Grid()
            {
                ShowGridLines = true
            };
            //添加3列
            grid.ColumnDefinitions.Add(new ColumnDefinition());
            grid.ColumnDefinitions.Add(new ColumnDefinition());
            grid.ColumnDefinitions.Add(new ColumnDefinition());
            //添加3行
            grid.RowDefinitions.Add(new RowDefinition());
            grid.RowDefinitions.Add(new RowDefinition());
            grid.RowDefinitions.Add(new RowDefinition());

            Button button = new Button() { Content = "OK"};
            Grid.SetColumn(button,1);
            Grid.SetRow(button, 1);

            grid.Children.Add(button);
            this.Content = grid;
        }
    }
}
